图像二值化、提取边缘

这段代码用于LCD数字数据集的灰度和二值化处理。通过OpenCV库,应用高斯模糊、Otsu二值化等方法对图像进行预处理,同时展示了如何使用自适应阈值提取图像边缘。最后,将处理后的图像保存为JPEG格式。
摘要由CSDN通过智能技术生成
# -*- coding:utf-8 -*-
'''
@finish time:20170914
@author;fengjiexyb
this code is used for my lcd digit dataset gray and binarization
'''

import pickle
from svmutil import *
from PCV.tools import imtools
import numpy as np
import struct
import matplotlib.pyplot as plt
import random
import logging
import os
from PIL  import Image
import cv2
path='C:/Users/fengjiexyb/Desktop/ttt/'
files=os.listdir(path)
features=[]
label = []
for index in files:
    image=Image.open(path+index)
    imNew=np.array(image.resize((50,50)).convert('L'))
    thresh = 10
    maxValue = 255
    #binarization used ostu in three lower lines
    blur = cv2.GaussianBlur(imNew, (5, 5), 0)
    ret3, dst = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
    Image.fromarray(dst).save('new' + index, 'jpeg')

    # 以下两行二值化的效果不如ostu
    # 具体参数参考ht
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值